package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.HouseMainBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

public class HousePublishMainAdapter extends BaseQuickAdapter<HouseMainBean,BaseViewHolder> {
    ItemCallBack mitemCallBack;
    public HousePublishMainAdapter(@Nullable List<HouseMainBean> data,ItemCallBack itemCallBack) {
        super(R.layout.housepublishmain_item,data);

        mitemCallBack=itemCallBack;
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseMainBean item) {
       helper.<TextView>getView(R.id.housepublishmain_item_title).setText(item.getTitle());
       helper.<RecyclerView>getView(R.id.housepublishmain_item_RecyclerView).setLayoutManager(new GridLayoutManager(mContext,3));
        helper.<RecyclerView>getView(R.id.housepublishmain_item_RecyclerView).addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(20)));
        HousePublishMainItemAdapter adapter=new HousePublishMainItemAdapter(item.getHouseMainItems());
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                mitemCallBack.callBack((HouseMainBean.HouseMainItem)adapter.getData().get(position));
            }
        });
        helper.<RecyclerView>getView(R.id.housepublishmain_item_RecyclerView).setAdapter(adapter);
    }

    public interface ItemCallBack{
        void callBack(HouseMainBean.HouseMainItem houseMainItem);
    }
}
